package com.jcxy.controller;

import com.jcxy.VO.*;
import com.jcxy.mapper.ProcessMapper;
import com.jcxy.pojo.BurseDetail;
import com.jcxy.pojo.User;
import com.jcxy.service.ProcessService;
import com.jcxy.util.PageBean;
import com.jcxy.util.ParamsDto;
import com.jcxy.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/myProcess")
public class MyProcessController {

    @Autowired
    private ProcessService processService;
    @Autowired
    private ProcessMapper processMapper;

    /**
     * 通过分页获得登录用户的流程列表
     * @return
     */
    @RequestMapping("/getMyProcessListByPage.do")
    @ResponseBody
    public ResponseData getMyProcessListByPage(HttpServletRequest request){


        //将参数转换成合适的map集合
        Map dto = ParamsDto.getDto(request.getParameterMap());
        //获取登录对象
        User user = (User) request.getSession().getAttribute("user");
        dto.put("user_id",user.getUser_id());

        //调用业务逻辑层方法，查询角色列表
        PageBean pageBean = processService.queryListByPage(
                dto,//查询条件
                Integer.valueOf(dto.get("page").toString()),//当前页
                Integer.valueOf(dto.get("limit").toString()));//页容量

        return pageBean.getResponseData();
    }

    /**
     * 跳转到burseForm.jsp页面
     * @param request
     * @return
     */
    @RequestMapping("/toShowBursePage.do")
    public String toShowBursePage(HttpServletRequest request){

        //将参数转换成合适的map集合
        Map dto = ParamsDto.getDto(request.getParameterMap());
        BurseVo burseVo = processMapper.queryBurseProcessById(Integer.valueOf(dto.get("process_id").toString()));

        request.setAttribute("burseVo",burseVo);
        return "processManage/burse/burseForm";
    }

    /**
     * 通过费用报销id，获取费用明细
     * @param burse_id
     * @return
     */
    @RequestMapping("/getBurseDetailById.do")
    @ResponseBody
    public ResponseData getBurseDetailById(Integer burse_id){

        List<BurseDetail> burseDetailList = processMapper.queryBurseDetailById(burse_id);

        ResponseData ok = ResponseData.ok();
        ok.setData(burseDetailList);
        ok.setCode(0);
        return ok;
    }

    /**
     * 跳转到evectionForm.jsp页面
     * @param request
     * @return
     */
    @RequestMapping("/toShowEvectionPage.do")
    public String toShowEvectionPage(HttpServletRequest request){

        //将参数转换成合适的map集合
        Map dto = ParamsDto.getDto(request.getParameterMap());
        EvectionVo evectionVo = processMapper.queryEvectionProcessById(Integer.valueOf(dto.get("process_id").toString()));

        request.setAttribute("evectionVo",evectionVo);

        return "processManage/evection/evectionForm";
    }

    /**
     * 跳转到overtimeForm.jsp页面
     * @param request
     * @return
     */
    @RequestMapping("/toShowOvertimePage.do")
    public String toShowOvertimePage(HttpServletRequest request){

        //将参数转换成合适的map集合
        Map dto = ParamsDto.getDto(request.getParameterMap());
        OvertimeVo overtimeVo = processMapper.queryOvertimeProcessById(Integer.valueOf(dto.get("process_id").toString()));

        request.setAttribute("overtimeVo",overtimeVo);

        return "processManage/overtime/overtimeForm";
    }

    /**
     * 跳转到regularForm.jsp页面
     * @param request
     * @return
     */
    @RequestMapping("/toShowRegularPage.do")
    public String toShowRegularPage(HttpServletRequest request){

        //将参数转换成合适的map集合
        Map dto = ParamsDto.getDto(request.getParameterMap());
        RegularVo regularVo = processMapper.queryRegularProcessById(Integer.valueOf(dto.get("process_id").toString()));

        request.setAttribute("regularVo",regularVo);

        return "processManage/regular/regularForm";
    }

    /**
     * 跳转到holidayForm.jsp页面
     * @param request
     * @return
     */
    @RequestMapping("/toShowHolidayPage.do")
    public String toShowHolidayPage(HttpServletRequest request){

        //将参数转换成合适的map集合
        Map dto = ParamsDto.getDto(request.getParameterMap());
        HolidayVo holidayVo = processMapper.queryHolidayProcessById(Integer.valueOf(dto.get("process_id").toString()));

        request.setAttribute("holidayVo",holidayVo);

        return "processManage/holiday/holidayForm";
    }

    /**
     * 跳转到resignForm.jsp页面
     * @param request
     * @return
     */
    @RequestMapping("/toShowResignPage.do")
    public String toShowResignPage(HttpServletRequest request){

        //将参数转换成合适的map集合
        Map dto = ParamsDto.getDto(request.getParameterMap());
        ResignVo resignVo = processMapper.queryResignProcessById(Integer.valueOf(dto.get("process_id").toString()));

        request.setAttribute("resignVo",resignVo);

        return "processManage/resign/resignForm";
    }
}
